package top.wintp.offlinedataanalysis.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * description:
 * <p>
 * author:  upuptop
 * <p>
 * qq: 337081267
 * <p>
 * CSDN:   http://blog.csdn.net/pyfysf
 * <p>
 * cnblogs:   http://www.cnblogs.com/upuptop
 * <p>
 * blog:   http://wintp.top
 * <p>
 * email:  pyfysf@163.com
 * <p>
 * time: 2019/08/2019/8/14
 * <p>
 */
public class HttpUtils {

    private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);

    /**
     * 将http请求的参数转为map
     *
     * @param param ver=1&pl=website&sdk=js&l=zh-CN&b_rst=1536*864
     * @return map
     */
    public static Map<String, String> conversionParam(String param) {

        Map<String, String> resultMap = new HashMap<>();


        String[] kv = param.split("\\&");

        for (String kvItem : kv) {
            String[] endKv = kvItem.split("=");

            if (endKv.length < 2) {
                logger.info("HttpUtils  conversionParam()   数据格式不正确   " + kvItem);
                continue;
            }

            resultMap.put(endKv[0], endKv[1]);
        }

        return resultMap;
    }
}
